<?php
require_once 'modules/content/models/Content.php';
require_once 'modules/content/models/ContentCategory.php';
require_once 'modules/ads/models/Ads.php';

class default_IndexController extends Nine_Controller_Action
{
	public function subscribeSuccessAction()
	{
		/**
         * Display tempalte
         */
        $this->view->headTitle('Subscribe Success');
        $this->view->errorEmail = $this->session->errorEmail;
        $this->session->errorEmail = null;
	}
	public function indexAction()
	{
		/**
         * Display tempalte
         */
		$this->setLayout('home');
        $this->view->headTitle('Home');
        $this->view->menuId = 'home';
        
        $objContent = new Models_Content();
        
        
        $about = $objContent->getContentById(205);
        
        $condition = array();
        $condition['content_category_gid'] = 23;
        $newIndex = $objContent->setAllLanguages(true)->getAllContent($condition,'content_id',4);
        foreach ($newIndex as &$item){
			if(null != @$item['images']) {
            		$item['main_image'] = explode('||', trim($item['images'],'|| '));
            		$item['main_image'] = current($item['main_image']);
		            		if(null != $item['main_image'] ) {
		            			$tmp = @explode(":", trim($item['main_image'],': '));
		            			$item['main_image'] = array(
					            			'path' => Nine_Function::getThumbImage(@$tmp[0], 210, 197,null,true),
					            			'title' => @$tmp[1],
					            			);
        			
            				}
        		}
        		$item['intro'] = Nine_Function::subStringAtBlank(trim(strip_tags($item['full_text'])),80);
        }
        unset($item);
//         echo "<pre>";print_r($newIndex);die;   	
        $this->view->about = $about;
        $this->view->newIndex = $newIndex;	
		
	}
	
    public function customerAction() {
    	$this->setLayout('front');
        $this->view->headTitle(Nine_Language::translate('Partner'));
        $this->view->menuId = 'partner';
        
            $numRowPerPage = Nine_Registry::getConfig("partnerNumberRowPerPage"); 
            $currentPage = $this->_getParam("page",1);
        
        
        
        /**
         * Get all Custommer
         */
        $objAds = new Models_Ads();
        
        $allPartner = $objAds->getAllAdsByCategory(1,null,array('sorting ASC'),
                                                                             $numRowPerPage,($currentPage - 1) * $numRowPerPage)->toArray();
//        echo "<pre>";print_r($allPartner);die;
        /**
         * Modified all customer
         */
        if (!empty($allPartner)) {
            foreach ($allPartner as &$customer) {
                if (null != @$customer['image']) {
                   $customer['images_main'] = Nine_Function::getThumbImage(@$customer[image], 288, 146,null,true);
                }
            }
        }
//        echo "<pre>";print_r($allPartner);die;
        $count = count($objAds->getAllAdsByCategory(1));
        $this->view->partner = $allPartner;
        $this->setPagination($numRowPerPage, $currentPage, $count); 
        
    }
}